package com.taotao.job.core.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * @author fanbeibei
 * @version 1.0
 * @date 2021/2/22 16:49
 */
@Getter
@AllArgsConstructor
public enum JobStatus {
    /**
     * cron 表达式不再触发
     */
    STOP_TRIGGER(0, "停止触发"),
    NORMAL_TRIGGER(1, "正常触发"),
    /**
     * 虽然到了cron的触发时间,但由于存在至少一个前置任务没有执行完，导致不能触发，等待前置任务全部执行完毕再立即触发
     */
    DELAY_TRIGGER(111, "延迟触发"),
    ;

    private Integer code;

    private String text;


    private static Map<Integer, JobStatus> codeTextMap = new HashMap<>();

    static {
        JobStatus[] values = JobStatus.values();
        for (JobStatus val : values) {
            codeTextMap.put(val.code, val);
        }
    }


    public static JobStatus getByCode(Integer code) {

        return codeTextMap.get(code);
    }

    public static String getTextByCode(Integer code) {
        JobStatus v = getByCode(code);

        if (null == v) {
            return "未知Code:" + code;
        }
        return v.text;
    }

}
